<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>INSPINIA | Basic Form</title>
    <link href="#springUrl('/static/css/bootstrap.min.css')" rel="stylesheet">
    <link href="#springUrl('/static/css/style.css')" rel="stylesheet">
</head>
<body class="white-bg">
<div class="ibox-content" style="width: 430px;">
    <form id="myForm" class="form-horizontal" autocomplete="off" data-validator-option="{theme:'default'}">
        <input type="hidden" name="id" value="$!{permission.id}">
<!--
        <input type="hidden" name="description" value="$!{permission.description}">
-->
        <input type="hidden" name="icon" value="$!{permission.icon}">
        <input type="hidden" name="permCode" value="$!{permission.permCode}">
        <div class="form-group"><label class="col-sm-2 control-label">标题</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="$!{permission.title}" name="title">
            </div>
        </div>

        <div class="form-group"><label class="col-sm-2 control-label">类型</label>
            <div class="col-sm-10">
                <select class="form-control m-b" name="pid">
                    #foreach($permissionTop in $permissionTopList)
                        #if($!{permission})
                            #if(${permissionTop.id}==${permission.pid})
                              <option  value="${permissionTop.id}" selected="selected">${permissionTop.title}</option>
                            #else
                              <option  value="${permissionTop.id}">2$!{permissionTop.title}</option>
                            #end
                        #else
                          <option  value="${permissionTop.id}">3$!{permissionTop.title}</option>
                        #end
                    #end
                </select>
            </div>
        </div>
        <div class="form-group"><label class="col-sm-2 control-label">描述</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="$!{permission.description}" name="description">
            </div>
        </div>
        <div class="form-group"><label class="col-sm-2 control-label">排序</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="$!{permission.sort}" name="sort">
            </div>
        </div>
        <div class="form-group"><label class="col-sm-2 control-label">地址Url</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="$!{permission.url}" name="url">
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <div class="text-center">
                <button class="btn btn-primary" type="submit">#if($!{user})修 改#else提 交#end</button>

                <button type="button" class="btn btn-default " onclick="closeAll()">关闭</button>
            </div>
        </div>
    </form>
</div>
<script src="#springUrl('/static/js/jquery-2.1.1.js')"></script>
<script src="#springUrl('/static/plugins/nice-validator-0.8.1/jquery.validator.js?local=zh-CN')"></script>
<script type="text/javascript">
    var index = parent.layer.getFrameIndex(window.name);
    $("#myForm").validator({
        valid: function(form){
            var me = this;
            // 提交表单之前，hold住表单，防止重复提交
            me.holdSubmit();
            $.ajax({
                url: "#springUrl('/perm/permission/editPerm')",
                dataType: "json",
                data:$(form).serialize(),
                type: "POST",
                success: function(data){
                    if(data.success && data.data){
                        parent.layer.alert("修改成功",function(){
                            parent.layer.closeAll();
                            window.parent.location.reload();
                        });
                        me.holdSubmit(false);
                    } else {
                        //失败，提交表单成功后，释放hold，如果不释放hold，就变成了只能提交一次的表单
                        me.holdSubmit(false);
                    }
                }
            });
        }
    });
    function closeAll() {
        //ifram层关闭自身，传入索引
        parent.layer.close(index);
    }
</script>
</body>
</html>
